tonic-build
Compiles proto files via prost and generates service stubs and proto definitions for use with tonic.
Features
Required dependencies
[]
= <tonic-version>
= <prost-version>
[]
= <tonic-version>
Examples
Simple
In build.rs
:
Configuration
Google APIs example
A good way to use Google API is probably using git submodules.
So suppose in our proto
folder we do:
git submodule add https://github.com/googleapis/googleapis
git submodule update --remote
And a bunch of Google proto files in structure will be like this:
├── googleapis
│ └── google
│ ├── api
│ │ ├── annotations.proto
│ │ ├── client.proto
│ │ ├── field_behavior.proto
│ │ ├── http.proto
│ │ └── resource.proto
│ └── pubsub
│ └── v1
│ ├── pubsub.proto
│ └── schema.proto
Then we can generate Rust code via this setup in our build.rs
Then you can reference the generated Rust like this this in your code:
use ;
Or if you want to save the generated code in your own code base,
you can uncomment the line .out_dir(...)
above, and in your lib file
config a mod like this:
See the example here